#pragma once
#include <memory>
#include <functional>
#include <unordered_map>
#include <vector>
#include "Acceptor.h"
#include "EventLoop.h"
#include "IPAddress.h"
#include "Socket.h"
#include "Connection.h"
#include "utils/ThreadPool.h"
#include "utils/Noncopyable.h"


namespace net
{

class TcpServer : public std::enable_shared_from_this<TcpServer> , Noncopyable
{
public:
    using ptr = std::shared_ptr<TcpServer>;

    TcpServer(EventLoop::ptr ptrEventLoop, IPAddress::ptr ptrAddr);
    virtual ~TcpServer();
    virtual void start();

    virtual void onNewConnection(Socket::ptr clientSock);
    virtual void onDeleteConnection(Socket::ptr clientSock);
    virtual void handleEvent(Connection::ptr ptrCon);

private:
    EventLoop::ptr m_mainReactor;
    std::vector<EventLoop::ptr> m_vecSubReactor;
    Acceptor::ptr m_ptrAcceptor;
    std::unordered_map<int, Connection::ptr> m_mapFd2Connection;
    ThreadPool::ptr m_ptrThreads;
};
    
} // namespace net